#include "absserver.h"
#include "msgsocket.h"
#include "command.h"
#include "databasemagr.h"

#include <QHostAddress>

///////////////////////////////////////////////////////////////////////////////
/// \brief MsgServer::MsgServer
/// \param parent
///
AbsServer::AbsServer(QObject *parent) :
    QObject(parent)
{
    m_tcpServer = new QTcpServer(this);

    connect(m_tcpServer, SIGNAL(newConnection()),
            this, SLOT(SltNewConnection()));
}

AbsServer::~AbsServer()
{
    if (m_tcpServer->isListening()) m_tcpServer->close();
}

/**
 * @brief TcpServer::StartListen
 * 启动监听
 * @param port
 * @return
 */
bool AbsServer::StartListen(int port)
{
    if (m_tcpServer->isListening()) m_tcpServer->close();
    bool bOk = m_tcpServer->listen(QHostAddress::AnyIPv4, port);
    return bOk;
}

/**
 * @brief TcpServer::CloseListen
 * 关闭
 */
void AbsServer::CloseListen()
{
    m_tcpServer->close();
}
